package com.gxc.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Topic模式.
 *
 * @author GongXincheng
 * @since 2019-08-23 00:32
 */
@Configuration
public class TopicQueueConfigBean {

    public final static String MESSAGE_QUEUE = "topic.message";
    public final static String MESSAGES_QUEUE = "topic.messages";

    @Bean
    public Queue messageQueue() {
        return new Queue(MESSAGE_QUEUE);
    }

    @Bean
    public Queue messagesQueue() {
        return new Queue(MESSAGES_QUEUE);
    }

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("topicExchange", true, false);
    }

    @Bean
    Binding bindingExchangeMessage(Queue messageQueue, TopicExchange topicExchange) {
        return BindingBuilder.bind(messageQueue).to(topicExchange).with("topic.message");
    }

    @Bean
    Binding bindingExchangeMessages(Queue messagesQueue, TopicExchange topicExchange) {
        return BindingBuilder.bind(messagesQueue).to(topicExchange).with("topic.#");
    }
}
